package loader

import (
	"kumachan/interpreter/lang/textual/ast"
	"kumachan/interpreter/lang/textual/parser"
	"kumachan/interpreter/lang/textual/syntax"
	"kumachan/interpreter/lang/textual/transformer"
)


type SourceFile interface {
	GetAST() (*ast.Root, ErrorContent)
}
type SourceFileTextual struct {
	FileRef  FileRef
	Content  [] byte
}
func (f SourceFileTextual) GetAST() (*ast.Root, ErrorContent) {
	var code_string = string(f.Content)
	var code = ([] rune)(code_string)
	var path = f.FileRef.Path
	var syntax_root = syntax.DefaultRootPartName
	var tree, err = parser.Parse(code, syntax_root, path)
	if err != nil { return nil, E_ParseFailed { ParserError: err } }
	var root = transformer.Transform(tree).(ast.Root)
	LoadAssets(&root, f.FileRef)
	return &root, nil
}
// TODO: structural


